' Menu flags for Add/Check/EnableMenuItem() Global Const MF_INSERT = &H0 Global Const MF_CHANGE = &H80 Global Const MF_APPEND = &H100 Global Const MF_DELETE = &H200 Global Const MF_REMOVE = &H1000 Global Const MF_BYCOMMAND = &H0 Global Const MF_BYPOSITION = &H400 Global Const MF_SEPARATOR = &H800 Global Const MF_ENABLED = &H0 Global Const MF_GRAYED = &H1 Global Const MF_DISABLED = &H2 Global Const MF_UNCHECKED = &H0 Global Const MF_CHECKED = &H8 Global Const MF_USECHECKBITMAPS = &H200 Global Const MF_STRING = &H0 Global Const MF_BITMAP = &H4 Global Const MF_OWNERDRAW = &H100 Global Const MF_POPUP = &H10 Global Const MF_MENUBARBREAK = &H20 Global Const MF_MENUBREAK = &H40 Global Const MF_UNHILITE = &H0 Global Const MF_HILITE = &H80 Global Const MF_SYSMENU = &H2000 Global Const MF_HELP = &H4000 Global Const MF_MOUSESELECT = &H8000 ' Menu item resource format Type MENUITEMTEMPLATEHEADER versionNumber As Integer offset As Integer End Type Type MENUITEMTEMPLATE mtOption As Integer mtID As Integer mtString As Long End Type Global Const MF_END = &H80 ' System Menu Command Values Global Const SC_SIZE = &HF000 Global Const SC_MOVE = &HF010 Global Const SC_MINIMIZE = &HF020 Global Const SC_MAXIMIZE = &HF030 Global Const SC_NEXTWINDOW = &HF040 Global Const SC_PREVWINDOW = &HF050 Global Const SC_CLOSE = &HF060 Global Const SC_VSCROLL = &HF070 Global Const SC_HSCROLL = &HF080 Global Const SC_MOUSEMENU = &HF090 Global Const SC_KEYMENU = &HF100 Global Const SC_ARRANGE = &HF110 Global Const SC_RESTORE = &HF120 Global Const SC_TASKLIST = &HF130 Global Const SC_ICON = SC_MINIMIZE Global Const SC_ZOOM = SC_MAXIMIZE Declare Function LoadMenu Lib "User" (ByVal hInstance As Integer, ByVal lpString As String) As Integer Declare Function LoadMenuIndirect Lib "User" (lpMenuTemplate As MENUITEMTEMPLATE) As Integer Declare Function GetMenu Lib "User" (ByVal hWnd As Integer) As Integer Declare Function SetMenu Lib "User" (ByVal hWnd As Integer, ByVal hMenu As Integer) As Integer Declare Function ChangeMenu Lib "User" (ByVal hMenu As Integer, ByVal wId As Integer, ByVal lpszNew As String, ByVal wIDNew As Integer, ByVal wChange As Integer) As Integer Declare Function HiliteMenuItem Lib "User" (ByVal hWnd As Integer, ByVal hMenu As Integer, ByVal wIDHiliteItem As Integer, ByVal wHilite As Integer) As Integer Declare Function GetMenuString Lib "User" (ByVal hMenu As Integer, ByVal wIDItem As Integer, ByVal lpString As String, ByVal nMaxCount As Integer, ByVal wFlag As Integer) As Integer Declare Function GetMenuState Lib "User" (ByVal hMenu As Integer, ByVal wId As Integer, ByVal wFlags As Integer) As Integer Declare Sub DrawMenuBar Lib "User" (ByVal hWnd As Integer) Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer Declare Function CreateMenu Lib "User" () As Integer Declare Function CreatePopupMenu Lib "User" () As Integer Declare Function DestroyMenu Lib "User" (ByVal hMenu As Integer) As Integer Declare Function CheckMenuItem Lib "User" (ByVal hMenu As Integer, ByVal wIDCheckItem As Integer, ByVal wCheck As Integer) As Integer Declare Function EnableMenuItem Lib "User" (ByVal hMenu As Integer, ByVal wIDEnableItem As Integer, ByVal wEnable As Integer) As Integer Declare Function GetSubMenu Lib "User" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer Declare Function GetMenuItemID Lib "User" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer Declare Function GetMenuItemCount Lib "User" (ByVal hMenu As Integer) As Integer Declare Function InsertMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer Declare Function AppendMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer Declare Function ModifyMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpString As Any) As Integer Declare Function RemoveMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer Declare Function DeleteMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer Declare Function SetMenuItemBitmaps Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal hBitmapUnchecked As Integer, ByVal hBitmapChecked As Integer) As Integer Declare Function GetMenuCheckMarkDimensions Lib "User" () As Long Declare Function TrackPopupMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nReserved As Integer, ByVal hWnd As Integer, lpReserved As Any) As Integer DefInt A-Z Dim LMenu As Integer Sub AddApp_Click () Msg$ = "Enter Path:" FileSpec$ = InputBox$(Msg$) LMenu = LMenu + 1 Load AppName(LMenu) AppName(LMenu).Caption = FileSpec$ End Sub Sub AddMenuItem_Click () '-- add the new menu item LMenu = LMenu + 1 Load AppName(LMenu) '-- set the appropriate properties ahWnd = Form1.hWnd MenuCaption$ = MenuText.Text Result = SetMenuItem(ahWnd, 0, LMenu + 2, MenuCaption$, -SepBarCheck.Value) End Sub Sub SetItem_Click () '-- sets a previously existing menu item ahWnd = Form1.hWnd MenuCaption$ = MenuText.Text Result = SetMenuItem(ahWnd, Val(SubMenu.Text), Val(MenuItem.Text), MenuCaption$, -SepBarCheck.Value) End Sub Sub ExitProgram_Click () End End Sub Sub UpdateItemInfo () '-- update the caption text and Separator Bar checkbox ahWnd = Form1.hWnd nSubMenu = Val(SubMenu.Text) nItemPos = Val(MenuItem.Text) MenuText.Text = MenuItemCaption(ahWnd, nSubMenu, nItemPos) SepBarCheck.Value = SepBar(ahWnd, nSubMenu, nItemPos) End Sub Sub MenuItem_LostFocus () UpdateItemInfo End Sub Sub SubMenu_LostFocus () UpdateItemInfo End Sub DefInt A-Z Function SetMenuItem (ahWnd As Integer, nSubPos As Integer, nItemPos As Integer, MenuItem$, fSepBar As Integer) As Integer '-- Sets the MenuItem in SubMenu nSubPos at position nItemPos ' with the appropriate caption MenuItem$ and being a separator bar ' if SepBar is TRUE, or not a separator bar if SepBar is FALSE '-- get the item ID number wMenuID = MenuItemID(ahWnd, nSubPos, nItemPos) '-- MF_BYCOMMAND means that we're using the menu item ID, not position '-- get the current menu item flags using the menu item ID wMenuFlags = GetMenuState(hMenu, wMenuID, MF_BYCOMMAND) If fSepBar Then '-- turn MF_SEPARATOR on wMenuFlags = wMenuFlags Or MF_SEPARATOR Else '-- turn MF_SEPARATOR off wMenuFlags = wMenuFlags And Not MF_SEPARATOR End If '-- we always locate via the menu item ID wMenuFlags = wMenuFlags Or MF_BYCOMMAND '-- modify the menu item and return the result back to the caller SetMenuItem = ModifyMenu(hMenu, wMenuID, wMenuFlags, wMenuID, MenuItem$) End Function Function MenuItemCaption (ahWnd As Integer, nSubPos As Integer, nItemPos As Integer) As String '-- get the handle to the menu hMenu = GetMenu(ahWnd) '-- get the menu item ID wMenuIDItem = MenuItemID(ahWnd, nSubPos, nItemPos) '-- allocate space for menu item caption Temp$ = Space$(40) StrLen = GetMenuString(hMenu, wMenuIDItem, Temp$, Len(Temp$), MF_BYCOMMAND) MenuItemCaption$ = Left$(Temp$, StrLen) End Function Function MenuItemID (ahWnd As Integer, nSubPos As Integer, nItemPos As Integer) As Integer '-- get the handle to the menu hMenu = GetMenu(ahWnd) '-- get the handle to the SubMenu hSubMenu = GetSubMenu(hMenu, nSubPos) '-- get the menu item ID MenuItemID = GetMenuItemID(hSubMenu, nItemPos) End Function Function SepBar (ahWnd As Integer, nSubPos As Integer, nItemPos As Integer) As Integer '-- get the handle to the menu hMenu = GetMenu(ahWnd) '-- get the item ID number wMenuID = MenuItemID(ahWnd, nSubPos, nItemPos) '-- get the flags for the item wMenuFlags = GetMenuState(hMenu, wMenuID, MF_BYCOMMAND) '-- return a 1 (TRUE) or 0 (FALSE) state value for the separator bar SepBar = Abs((wMenuFlags And MF_SEPARATOR) <> 0) End Function